<template>
	<view class="user">
		<view class="top">
			<image v-if="is_login" src="/static/index/head.jpg" mode="" class="header_logo"></image>
			<image v-else src="../../static/index/header.png" mode="" class="header_logo"></image>
			<view class="userinfo">
				<view class="title">
					<text class="name" v-if="is_login">{{userinfo.username}}</text>
					<text class="name" @click="tologin" v-else>未登录</text>
					<view class="level">
						<image src="/static/index/hg.png" mode=""></image>
						{{userinfo.level_name}}
					</view>
					<!-- <image class="share" src="/static/index/share.png" mode=""></image> -->
				</view>
				
				<view class="phone" v-if="is_login">
					<text>{{userinfo.phone}}</text>
					<text>到期时间:{{userinfo.end}}</text>
				</view>
				<view class="phone" v-else>
					****
				</view>
				<view class="code">
					<text class="code-text" v-if="isshow">邀请码：{{ userinfo.recommend_code}}</text>
					<text class="code-text" v-else>邀请码：******</text>
					<view class="copy" @click="copy">
						复制
					</view>
					<image src="/static/index/2.png" v-if="isshow" mode="" @click="changeShow"></image>
					<image src="/static/index/3.png" v-else mode="" @click="changeShow"></image>
				</view>
			</view>
		</view>
		<view class="wallet">
			<view class="tixian">
				奖金：￥<text>{{Number(userinfo.Withdraw)}}</text>
			</view>
			<!-- <view class="tixian">
				总消费金额：￥<text>{{Number(userinfo.allmoney)}}</text>
			</view> -->
			<view class="tixian_now" @click="toPage('/pages/withdraw/index')">
				立即提现
			</view>
			<view class="wallet_info">
				<view class="info-item">
					<text>余额</text>
					<text>￥{{Number(userinfo.balance_1)}}</text>
				</view>
				
				<view class="info-item">
					<text>推广收益</text>
					<text>￥{{Number(userinfo.reward1)}}</text>
				</view>
				<!-- <view class="info-item">
					<text>分红收益</text>
					<text>$2635.02</text>
				</view> -->
			</view>
		</view>
		<view class="order">
			<view class="title">
				<text class="h3">我的订单</text>
				<text class="all" @click="toPage('/pages/order/index?id=0')">全部></text>
			</view>
			<view class="tips">
				<view class="tips-item" v-for="(item,index) in tipslist"
					@click="toPage('/pages/order/index?id='+item.id)" :key='index'>
					<image :src="item.img" mode=""></image>
					<text>{{item.name}}</text>
				</view>
			</view>
		</view>

		<view class="order sever">
			<view class="title">
				<text class="h3">常用功能</text>
				<!-- <text class="all" >全部></text> -->
			</view>
			<view class="tips">
				<view class="tips-item" @click="toPage('/pages/userteam/index')">
					<image src="../../static/index/s1.png" mode=""></image>
					<text>我的团队</text>
				</view>
				<view class="tips-item" @click="toPage('/pages/userbank/index')">
					<image src="../../static/index/s2.png" mode=""></image>
					<text>提现信息</text>
				</view>
				<view class="tips-item" @click="toPage('/pages/finance/index')">
					<image src="../../static/index/s3.png" mode=""></image>
					<text>账户明细</text>
				</view>
				<view class="tips-item" @click="toPage('/pages/usersetup/index')">
					<image src="../../static/index/s4.png" mode=""></image>
					<text>个人资料</text>
				</view>
				<view class="tips-item" @click="toPage('/pages/xieyi/index')">
					<image src="../../static/index/xieyi.png" mode=""></image>
					<text>用户协议</text>
				</view>
				<!-- <view class="tips-item">
					<image src="../../static/index/s6.png" mode=""></image>
					<text>我的认证</text>
				</view> -->
				<view class="tips-item" @click="toPage('/pages/addFeedback/index')">
					<image src="../../static/index/s7.png" mode=""></image>
					<text>在线留言</text>
				</view>
				<view class="tips-item" @click="toPage('/pages/kefu/index')">
					<image src="../../static/index/s6.png" mode=""></image>
					<text>联系客服</text>
				</view>
				<view class="tips-item" @click="toPage('/pages/addresslist/index')">
					<image src="../../static/index/s8.png" mode=""></image>
					<text>收货地址</text>
				</view>
				<view class="tips-item" @click="outlogin" v-if="is_login">
					<image src="../../static/index/s5.png" mode=""></image>
					<text>退出登录</text>
				</view>


			</view>
		</view>

	</view>
</template>

<script>
	import uniCopy from '@/components/js_sdk/xb-copy/uni-copy.js'
	import {
		checkLogin,
		loginOut
	} from '../../api/login.js'
	import {
		UserInfo
	} from '../../api/api.js'
	export default {
		data() {
			return {
				isshow: false,
				codenum: '',
				is_login: false,
				userinfo: {
					reward1: 0,
					balance_4: 0,
					level_name: '游客',
					Withdraw:0,
					balance_1:0,
					des:''
				},
				tipslist: [{
						'id': 1,
						'name': '全部',
						'img': '/static/index/order1.png'
					},
					{
						'id': 2,
						'name': '待付款',
						'img': '/static/index/order2.png'
					},
					{
						'id': 3,
						'name': '待发货',
						'img': '/static/index/order3.png'
					},
					{
						'id': 4,
						'name': '待收货',
						'img': '/static/index/order4.png'
					},
					{
						'id': 5,
						'name': '已完成',
						'img': '/static/index/order5.png'
					},

				]
			}
		},
		onLoad() {

		},
		onShow() {
			this.checkLogin()
			this.UserInfo()

		},
		methods: {
			outlogin() {
				loginOut()
				this.userinfo.reward1 = 0
				this.userinfo.balance_4 = 0
				this.userinfo.level_name = '游客'
				this.checkLogin()
				

			},
			UserInfo() {
				UserInfo().then(res => {
					
					if (res.status == 400) {
						uni.removeStorageSync('token')
					} else {
						this.userinfo = res.info
						this.codenum = this.userinfo.recommend_code
					}

				})
			},
			tologin() {
				uni.navigateTo({
					url: '/pages/login/index'
				})
			},
			checkLogin() {
				if (checkLogin()) {
					this.is_login = true
				} else {
					this.is_login = false
				}
				
			},
			changeShow() {
				if(this.is_login == true){
					this.isshow = !this.isshow
				}
			},
			copy() {
				uniCopy({
					content: this.websiteUrl + '#/pages/register/index?recommend=' + this.codenum + '&&des=' + this.userinfo.des,
					success: (res) => {
						uni.showToast({
							title: res,
							icon: 'none'
						})
					},
					error: (e) => {
						uni.showToast({
							title: e,
							icon: 'none',
							duration: 3000,
						})
					}
				})
			},
			toPage(url) {
				if (!this.is_login) {
					uni.navigateTo({
						url: '/pages/login/index'
					})
				} else {
					uni.navigateTo({
						url: url
					})
				}

			}
		}
	}
</script>

<style lang="scss">
	.user {
		background: #f7f7f7;
	}

	.top {
		padding-top: 20rpx;
		display: flex;
		padding-left: 5%;
		background: #1D3F2B;
		padding-bottom: 60px;

		.header_logo {
			height: 60px;
			width: 60px;
			border-radius: 50%;
		}

		.userinfo {
			color: #fff;
			flex: 1;
			margin-left: 3%;
			background: url(@/static/index/tiaowen.png);
			background-size: 100% 100%;

			.title {
				display: flex;
				align-items: center;

				image {
					width: 40rpx;
					height: 40rpx;
				}

				.name {
					display: block;
					width: 200rpx;
					font-size: 16px;
					max-width: 200rpx;
					overflow: hidden;
					text-overflow: ellipsis;
					white-space: nowrap;
				}

				.level {
					position: relative;
					background: linear-gradient(90deg, #FFEBC0, #FFC479);
					color: #6C2A09;
					border-radius: 40rpx;
					padding: 0 5%;
					font-size: 24rpx;
					line-height: 40rpx;
					margin-left: 20%;

					image {
						position: absolute;
						left: -18rpx;
						top: 0;
					}
				}

				.share {
					margin-left: 15%;
				}
			}
			
			.phone {
				font-size: 24rpx;
				margin: 30rpx 0;
				width: 75%;
				display: flex;
				justify-content: space-between;
			}

			.code {
				display: flex;
				align-items: center;

				.code-text {
					font-size: 13px;
					max-width: 55%;
					display: block;
				}

				.copy {
					background: #F1D3A8;
					color: #6C2A09;
					padding: 1% 3%;
					border-radius: 5px;
					font-size: 13px;
					margin-left: 5%;
				}

				image {
					width: 32rpx;
					height: 26rpx;
					margin-left: 10%;
				}
			}
		}

	}

	.wallet {
		background: url(../../static/index/card.png);
		background-size: 100% 100%;
		width: 96%;
		margin: 0 auto;
		margin-top: -40px;
		padding-bottom: 20px;
		font-size:20px ;
		color: #fff;
		// height: 330rpx;
		position: relative;

		.tixian {
			padding-top: 20px;
			font-size: 16px;
			padding-left: 5%;

			text {
				font-size: 20px;
			}
		}

		.tixian_now {
			position: absolute;
			right: 5%;
			top: 15%;
			border-radius: 20px;
			background: #ffffffb3;
			color: #C6A06F;
			padding: 1% 4%;
			font-size: 28rpx;
		}

		.wallet_info {
			display: flex;
			justify-content: space-around;
			text-align: center;
			margin-top: 40rpx;

			view {
				width: 50%;
				display: flex;
				flex-direction: column;
				border-right: 1px solid #fff;

				&:last-child {
					border: 0;
				}
			}
		}
	}

	.order {
		padding: 0 5%;
		margin-top: 30rpx;
		background: #fff;
		padding-bottom: 40rpx;

		.title {
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding: 5% 0;
			border-bottom: 1px solid #efefef;

			.h3 {
				font-weight: bold;
				color: #000;
				font-size: 16px;
			}

			.all {
				color: #999999;
				font-size: 14px;
			}
		}

		.tips {
			display: flex;
			justify-content: space-around;
			margin-top: 30rpx;

			.tips-item {
				display: flex;
				justify-content: center;
				align-items: center;
				flex-direction: column;

				image {
					width: 45rpx;
					height: 45rpx;
				}

				text {
					font-size: 14px;
					margin-top: 10rpx;
					color: #777777;
				}
			}
		}
	}

	.sever {
		.tips {
			display: table;
			width: 100%;
		}

		.tips-item {
			float: left;
			width: 25%;
			margin-bottom: 30rpx;
		}
	}
</style>
